package com.example.service;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.example.entity.ZyzComment;
import com.example.mapper.ZyzCommentMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 评论表业务层
 */
@Service
public class ZyzCommentService {
    @Autowired
    private ZyzCommentMapper zyzCommentMapper;

    /**
     * 评论
     * @param zyzComment
     * @return
     */
    public int add(ZyzComment zyzComment) {
        zyzComment.setAddTime(new Date());
        int i = zyzCommentMapper.insert(zyzComment);
        return i;
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    public int deleteBatch(String ids) {
        return zyzCommentMapper.deleteBatch(Convert.toStrArray(ids));

    }

    /**
     * 修改
     * @param zyzComment
     */
    public void updateById(ZyzComment zyzComment) {
        zyzCommentMapper.updateById(zyzComment);
    }

    /**
     * 查询所有
     * @param zyzComment
     * @return
     */
    public List<Map<String, Object>> selectAll(ZyzComment zyzComment) {
        return zyzCommentMapper.selectAll(zyzComment);
    }

    /**
     * 分页查询
     * @param zyzComment
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageInfo<Map<String, Object>> selectPage(ZyzComment zyzComment, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> maps = zyzCommentMapper.selectAll(zyzComment);
        return PageInfo.of(maps);
    }
}
